package org.gd.helloconcurrent.collision;

import java.util.concurrent.*;

public class SimpleExecutor {

    private static final int N_THREADS = 2;

    public static void main(String...a) {
        try {
            ExecutorService executor = Executors.newFixedThreadPool(N_THREADS);
            for (int i = 0; i < 10; i++) {
                Runnable runnable = new SimpleCallable();
                executor.submit(runnable);
                Callable callable = new SimpleCallable();
                executor.submit(callable);
                //SimpleCallable simpleCallable = new SimpleCallable();
                //executor.submit(simpleCallable);
            }
            executor.shutdown();
            while (!executor.isTerminated()) {}
        } finally {}
    }

    private static class SimpleCallable implements Callable, Runnable {
        @Override
        public Object call() throws Exception {
            System.out.println("call");
            return null;
        }
        @Override
        public void run() {
            System.out.println("run");
        }
    }
}
